<template>
    <div class="login-wrap">
        <el-container style="padding: 0px;background-color:rgb(238, 243, 250);">
            <login-logo :proName="proName"/>
            <el-main style="padding:0px;height: 100%;overflow:hidden;">
                <login-content @login="login"/>
            </el-main>
            <el-footer style="padding:0px;width:100%;">
                <login-footer/>
            </el-footer>
        </el-container>
    </div>
</template>

<script>
    import LoginSrv from "./api/login.service";
    import LoginLogo from "@/frames/dashboard/components/login/loginHeader";
    import LoginContent from "@/frames/dashboard/components/login/loginContent";
    import loginFooter from "@/frames/dashboard/components/login/loginFooter";

    export default {
        components: {
            LoginLogo,
            LoginContent,
            loginFooter
        },
        data() {
            return {
                proName: "",
                tenantList: [],
                timer: null
            };
        },
        methods: {
            async login(params) {
                let _this = this;
                await LoginSrv.getToken(params)
                    .then(async res => {
                        sessionStorage.setItem("userId", res.user_id);
                        sessionStorage.setItem("username", res.username);
                        sessionStorage.setItem("token", res.access_token);
                        sessionStorage.setItem("refresh_token", res.refresh_token);
                        sessionStorage.setItem("isLogTimeOver", false);
                        sessionStorage.setItem("isUserOver", false);
                        // 登录成功之后需要调取用户信息，存全局
                       await this.getUserInfo()
                        this.$router.push("/B1Home");
                        this.$store.dispatch("assemblePuzzles");
                        console.log('获取登陆信息',res.role_code)
                         this.$router.go(0)
                    })
                    .catch(error => {
                        this.$message.error(error.response.data.msg)
                    });
            },
           async getUserInfo(){
             let res  = await LoginSrv.getInfo()
             if (res.code !== 10200) {
                this.$message.error(res.msg);
            }else{
                sessionStorage.setItem("allUserInfo", JSON.stringify(res.data));
                sessionStorage.setItem("permissions", JSON.stringify(res.data.permissions));
                sessionStorage.setItem("isTipPassUpdate", JSON.stringify(res.data.isTipPassUpdate));
                sessionStorage.setItem("roleCodes", res.data.roleCodes)
            }
        }
        },
        created() {
        }
    };
</script>

<style scope>
    .login-wrap {
        display: flex;
        width: 100%;
        /* height: 1080px; */
        height: 100%;
    }

    .login-wrap .el-main {
        height: 100%;
        background: url(../assets/images/login/login_bg.png) no-repeat;
        background-size: 100% 100%;
    }

    .el-footer {
        position: fixed;
        bottom: 20px;
    }
</style>
